<template>
  <view style="width: 100%; min-height: 100vh;">
    <view style="width: 100%; padding: 0 60upx;">
      <view class="flex justify-between align-center"
            style="width: 100%; height: 98upx; border-bottom: 2upx solid #F8F8F8;">
        <view style="font-size: 26upx; color: #333333;">提现到银行卡</view>
        <view class="flex align-center">
          <input type="text" v-model="bank_card_number" disabled placeholder="未绑定"
                 style="text-align: right; font-size: 28upx; color: #999999;">
        </view>
      </view>
      <view class="flex flex-direction"
            style="width: 100%; height: 264upx; border-bottom: 2upx solid #F8F8F8; margin-bottom: 138upx;">
        <view class="flex align-center" style="height: 132upx; font-size: 26upx; color: #333333;">提现金额</view>
        <view class="flex align-center">
          <view style="font-size: 52upx; color: #121922;">￥</view>
          <view style="font-size: 72upx; color: #121922;">{{money}}</view>
        </view>
      </view>
    </view>
    <view style="padding: 0 74upx;">
      <view v-if="is_passed == 3 || is_passed == 1" @click="handleAllWithdraw()" class="flex align-center justify-center"
            style=" width: 100%; height: 80upx; background-color: #E52718; color: white; font-size: 28upx; border-radius: 40upx;">
        全部提现
      </view>
      <view v-if="!is_passed" class="flex align-center justify-center"
            style=" width: 100%; height: 80upx; background-color: #D8D8D8; color: white; font-size: 28upx; border-radius: 40upx;">
        审核中
      </view>
    </view>
    <!-- 弹出提示 -->
    <view class="cu-modal" :class="tip_flag?'show':''" @touchmove.stop.prevent="">
      <view class="cu-dialog bg-white" style="width: 462upx;">
        <view class="cu-bar justify-end">
          <view class="content">提示</view>
        </view>
        <view style="font-size: 28upx; color: #333333; margin-bottom: 34upx;">请先去绑定银行卡</view>
        <view class="flex align-center justify-center" @click="tip_flag = false"
              style="width: 100%; height: 72upx; border-top: 2upx solid #F8F8F8; font-size: 26upx; color: #E52718;">
          我知道了
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import {withdrawCash_getMoneyByUserId, settleApply_withdraw} from "api/bank/bank"
export default {
  data() {
    return {
      bank_card_number: '', //银行卡密码
      tip_flag: false, //提示
      money: '', //提现金额
      is_passed: '', //是否通过
    }
  },
  methods: {
    //初始化
    pageInit(){
      withdrawCash_getMoneyByUserId().then(res=>{
        console.log(res)
        this.money = res.data.money;
        this.is_passed = res.data.is_withdraw_cash;
        if(res.data.bank_account){
          let band_card = res.data.bank_account && res.data.bank_account.bank_account_no
          let top_few = band_card.substr(0,4);
          let last_few = band_card.substr(band_card.length - 4, band_card.length);
          this.bank_card_number = top_few + '****' + last_few;
        }
      })
    },
    //全部提现
    handleAllWithdraw() {
      if (!this.bank_card_number) {
        this.tip_flag = true;
        return;
      }
    if(!this.money){
      uni.showToast({
        title: '暂无可提现的金额',
        icon: 'none'
      })
      return;
    }
    if(this.is_passed == 1){
      uni.showToast({
        title: '您提现的金额正在审核中',
        icon: 'none'
      })
      return;
    }
      settleApply_withdraw({settle_fee: this.money}).then(res=>{
        this.pageInit();
        setTimeout(()=>{
          uni.showToast({
            title: '提现审核中',
            icon: 'none'
          })
        },500)
      }).catch(err=>{
        console.log(err)
        uni.showToast({
          title: err.msg,
          icon: 'none'
        })
      })
    }
  },
  onLoad(){
    this.pageInit();
  }
}
</script>

<style scoped>

</style>
